<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        使用单位-编辑
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../css/main.css" media="all">
    <script type="text/javascript" src="../../lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../../css/bootstrap.css">
    <link rel="stylesheet" href="../../lib/layui/css/layui_2.5.7.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .layui-table-page select {
            height: 22px;
        }
    </style>
</head>

<body>
<div id="app">
    <form class="layui-form x-center">
        <div class="layui-form-pane" style="margin-top: 15px; margin-left: 5%">
            <div class="layui-form-item">
                <div class="layui-form-item" id="area-picker" style="float: left">
                    <div class="layui-form-label"><span class='x-red'>*</span>省市地区</div>
                    <div class="layui-input-inline" style="width: 200px;">
                        <select lay-verify="required" name="province" class="province-selector" data-value=""
                                lay-filter="province-1">
                            <option value="">请选择省</option>
                        </select>
                    </div>
                    <div class="layui-input-inline" style="width: 200px;">
                        <select lay-verify="required" name="city" class="city-selector" data-value=""
                                lay-filter="city-1">
                            <option value="">请选择市</option>
                        </select>
                    </div>
                    <div class="layui-input-inline" style="width: 200px;">
                        <select lay-verify="required" name="county" class="county-selector" data-value=""
                                lay-filter="county-1">
                            <option value="">请选择区</option>
                        </select>
                    </div>
                </div>
                <input  autocomplete="off"  type="hidden" name="areaString" id="areaString" v-model="company.areaString" >
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"><span class='x-red'>*</span>使用单位</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" lay-verify="required" v-model="company.name" class="layui-input" name="name"
                           placeholder="使用单位">
                </div>

                <label class="layui-form-label"><span class='x-red'>*</span>通讯地址</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" lay-verify="required" v-model="company.address" class="layui-input"
                           name="address" placeholder="通讯地址">
                </div>

            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"><span class='x-red'>*</span>联系电话</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" lay-verify="required" v-model="company.persontel" class="layui-input"
                           name="persontel" placeholder="联系电话">
                </div>
                <label class="layui-form-label"><span class='x-red'>*</span>负责人员</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" lay-verify="required" v-model="company.responsiblePerson" class="layui-input"
                           name="responsiblePerson" placeholder="联系电话">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class='x-red'>*</span>客服电话</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" lay-verify="required" v-model="company.servicetel" class="layui-input"
                           name="servicetel" placeholder="客服电话">
                </div>
            </div>

            <div style="text-align: center" class="layui-form-item">
                <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                    保存
                </button>
            </div>
        </div>
    </form>


</div>
</body>

<script type="text/javascript" src="../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../js/myAjax.js"></script>
<script type="text/javascript" src="../../js/pub.js"></script>
<script type="text/javascript" src="../../lib/layui/layui2.5.7.js"></script>
<script type="text/javascript" src="../../js/vue.min.js"></script>
<!-- <script src="lib/layui/layui.js" charset="utf-8"></script> -->
<script src="../../js/x-layui.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>

<script>
    //配置插件目录
    layui.config({
        base: '../../js/'
        , version: '1.0'
    });
</script>
<script>
    layui.use(['laydate', 'element', 'laypage', 'layer', 'form'], function () {
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element;//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        okLoading.close($);
    });
</script>

<script>
    var recordId = getQueryVariable("recordId");



    layui.use(['laydate', 'form', 'layer','layarea'],
        function () {
            var $ = layui.jquery;
            var form = layui.form;
            var layer = layui.layer;
            var layarea = layui.layarea;
            var areaString = null;
            var vm = new Vue({
                el: "#app",
                data: {
                    company: {
                        id: null,
                        name: null,
                        address: null,
                        responsiblePerson: null,
                        persontel: null,
                        servicetel: null,
                        areaString: null,
                    }
                },
                created() {
                    if (recordId) {
                        let request1 = {
                            url: '/maintenance/company/detail',
                            data: {
                                userId: $userId,
                                id: recordId
                            },
                            method: "POST",
                        };
                        sendRequest(request1, (res) => {

                            this.company = res.data;
                            areaString = res.data.areaString;

                            var area = areaString.split(',');
                            layarea.render({
                                elem: '#area-picker',
                                data: {
                                    province: area[0],
                                    city: area[1],
                                    county: area[2],
                                },
                                change: function (res) {
                                    //选择结果
                                    console.log(res);
                                    if(res.province!=""){
                                        $("#areaString").val(res.province + "," + res.city + "," + res.county);
                                    }else{
                                        $("#areaString").val("");
                                    }
                                    form.render('select');
                                }
                            });

                        });
                    }

                },
                methods: {}
            });





            form.on('submit(sub)',
                function (data) {
                    let form = data.field;

                    form.userId = $userId;
                    form.id = vm.company.id;

                    let request = {
                        url: '/maintenance/company/add',
                        data: form,
                        method: "post",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.alert("操作成功", {
                                    icon: 6
                                },
                                function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.reload();

                                });
                        } else {
                            layer.alert(data.msg, {
                                icon: 5
                            })
                        }
                    });
                    return false;
                });
        });




</script>


</html>
